const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    nav: [
      { title: '报名管理', icon: 'email', url: './jiaoyu/baoming/list', color_id: 5, type: 'jiaoyu' },
      { title: '品牌管理', icon: 'safe', url: './car/brand/brand', color_id: 1, type: 'car' },
      { title: '车型报价管理', icon: 'chuzuche', url: './car/car/car', color_id: 2, type: 'car' },
      { title: '员工管理', icon: 'group-user', url: './car/member/member', color_id: 4, type: 'car' },
      { title: '交车图片管理', icon: 'thumb', url: './car/img/img', color_id: 5, type: 'car' },
      { title: '房型管理', icon: 'wangge', url: './hotel/room/room', color_id: 1, type: 'hotel' },
      { title: '预定管理', icon: 'qiandao', url: './hotel/order/order', color_id: 2, type: 'hotel' },
      { title: '商品管理', icon: 'gouwudai', url: './goods/list', color_id: 1},
      { title: '验单管理', icon: 'qrcode', url: './yan/list', color_id: 2 },
      { title: '优惠券管理', icon: 'gif', url: './coupon/list', color_id: 4 },
      { title: '订单管理', icon: 'log', url: './order/list', color_id: 6 },
      { title: '店铺管理', icon: 'edit', url: 'edit', color_id: 5 },
      //{ title: '直播管理', icon: 'video', url: './zhibo/list', color_id: 7 },
      { title: '我要提现', icon: 'doc', url: 'withdraw', color_id: 8},
      { title: '提现记录', icon: 'bbs', url: 'withdrawlist', color_id: 9 },
      { title: '教育咨询', icon: 'answer', url: './jiaoyu/answer/list', color_id: 1, type: 'jiaoyu' },
      { title: '学校公告', icon: 'doc', url: './jiaoyu/news/list', color_id: 2, type: 'jiaoyu' },
      { title: '金牌讲师', icon: 'bbs', url: './jiaoyu/member/list?type=teacher', color_id: 4, type: 'jiaoyu' },
      { title: '学员风采', icon: 'profile', url: './jiaoyu/member/list?type=student', color_id: 5, type: 'jiaoyu' },
      { title: '本周食谱', icon: 'meishi', url: './jiaoyu/food/list', color_id: 6, type: 'jiaoyu' },
      { title: '校园环境', icon: 'camera', url: './jiaoyu/news/add?type=huanjin', color_id: 1, type: 'jiaoyu' },
      { title: '关于我们', icon: 'camera', url: './jiaoyu/news/add?type=about', color_id: 1, type: 'jiaoyu' },
      { title: '案例管理', icon: 'doc', url: './jiancai/anli/list', color_id: 2, type: 'jiancai' },
      { title: '爆款管理', icon: 'zuanshi', url: './jiancai/baokuan/list', color_id: 1, type: 'jiancai' },
      { title: '店铺装修', icon: 'log', url: './link/link', color_id: 7 },
      { title: '预约管理', icon: 'edit', url: './yuguan/yuguan', color_id: 8 },
      { title: '外卖管理', icon: 'edit', url: 'waimai', color_id: 9, type: 'takeout'},
      { title: '会员卡管理', icon: 'log', url: './card/card', color_id: 9 },
      // { title: '会员卡管理', icon: 'log', url: './card/card', color_id: 9 },
      { title: '店铺管理', icon: 'edit', url: 'edit', color_id: 5, type: 'base'},
      { title: '店铺装修', icon: 'log', url: './link/link', color_id: 7,type: 'base' },
      { title: '优惠券管理', icon: 'gif', url: './coupon/list', color_id: 4, type: 'base'},
      // { title: '参与同城卡', icon: 'bbs', url: 'showABS', color_id: 5, type: 'jianncai' },
      // { title: '参与同城卡', icon: 'bbs', url: 'showABS', color_id: 5, type: 'jiaoyu' },
      // { title: '参与同城卡', icon: 'bbs', url: 'showABS', color_id: 5, type: 'car' },
      // { title: '参与同城卡', icon: 'bbs', url: 'showABS', color_id: 5, type: 'hotel' }
      { title: '参与同城卡', icon: 'bbs', url: 'showABS', color_id: 5 },
      { title: '店员管理', icon: 'qrcode', url: 'clerk/clerk', color_id: 6 },
      //{ title: '积分管理', icon: 'drop-sort', url: './integral/integral', color_id: 8, type: 'base' },
      { title: '积分管理', icon: 'drop-sort', url: './integral/integral', color_id: 8, },
    ],
    nav_vip:[
      { title: '行业店铺', icon: 'vip', url: './jiaoyu/baoming/list', color_id: 7, type: '', type_num: 0 },
      { title: '独立小程序', icon: 'hot', url: './jiaoyu/baoming/list', color_id: 8, type: '', type_num: 1},
      { title: '独立小程序', icon: 'hot', url: './jiaoyu/baoming/list', color_id: 8, type: 'jiancai', type_num: 1},
      { title: '独立小程序', icon: 'hot', url: './jiaoyu/baoming/list', color_id: 8, type: 'jiaoyu', type_num: 1},
      { title: '独立小程序', icon: 'hot', url: './jiaoyu/baoming/list', color_id: 8, type: 'car', type_num: 1},
      { title: '独立小程序', icon: 'hot', url: './jiaoyu/baoming/list', color_id: 8, type: 'hotel', type_num: 1},
      // { title: '直播', icon: 'video', url: './zhibo/list', color_id: 7, type: 'base'},
      { title: '会员卡', icon: 'v1', url: './zhibo/list', color_id: 1, type: 'base', type_num: 2},
      { title: '营销功能', icon: 'log', url: './zhibo/list', color_id: 2, type: 'base', type_num: 3},
      { title: '全景', icon: 'drop-sort', url: './zhibo/list', color_id: 3, type: 'base', type_num: 4},
      { title: '视频', icon: 'video', url: './zhibo/list', color_id: 4, type: 'base', type_num: 5},
      { title: '裂变推广', icon: 'star', url: './zhibo/list', color_id: 5, type: 'base', type_num: 6},
      { title: '一键推送', icon: 'tearch', url: './zhibo/list', color_id: 6, type: 'base', type_num: 7},
      { title: '专属圈子', icon: 'earth', url: './zhibo/list', color_id: 7, type: 'base', type_num: 8},
      { title: '预约', icon: 'finding', url: './zhibo/list', color_id: 8, type: 'base', type_num: 9},
      { title: '行业店铺', icon: 'vip', url: './zhibo/list', color_id: 7, type: 'base', type_num: 10},
      { title: '独立小程序', icon: 'hot', url: './zhibo/list', color_id: 8, type: 'base', type_num: 1},
    ],
    showShopJoinAgreement: 0,
    is_clerk: false
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    //店员处理
    var real_openid = app.globalData.openid
    if (options.is_clerk != 'undefined' && options.is_clerk == '1') {
      console.log(options.openid)
      real_openid = options.openid
      that.setData({
        nav:[
          { title: '验单管理', icon: 'qrcode', url: './yan/list', color_id: 2 }
        ],
        nav_vip: [],
        is_clerk: true
      })
    }
    wx.showLoading({
      title: '加载中…',
    })
    app.ihttpGet('https://www.58zltc.com/api.php/ShopAdmin/getInfo/openid/' + real_openid, function(res){
      if(res.data.type =='takeout'){
        wx.navigateTo({
          url: 'waimai',
        })
        return false;
      }
      app.ihttpGet('https://www.58zltc.com/api.php/ShopAdmin/verJoinEndTime/shop_id/' + res.data.shop_id, function (resq) {
        that.setData({
          verJoinEndTime: resq.data
        })
      })
      that.setData({
        info: res.data,
        shop_id:res.data.shop_id
      })
      app.ihttpGet('https://www.58zltc.com/api.php/Shop/getCardInfo/shop_id/' + res.data.shop_id, function (resqq) {
        var navt = that.data.nav;
        if (resqq.data.status == 1) {
          for (var i = 0; i < navt.length; i++) {
            if (navt[i].title == '参与同城卡') {
              console.log(navt[i].title + i)
              navt[i].title = '管理同城卡'
            }
          }
        }
        that.setData({
          nav: navt
        })
      })
      wx.hideLoading();
    })
    //商户参与同城卡协议内容
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/getShopJionAgreement', function (resq) {
      var data = resq.data;
      var WxParse = require('../../../wxParse/wxParse.js');
      var article = data.content;
      WxParse.wxParse('article', 'html', article, that, 5);
    })
  },
  openshopcard:function(){
    var that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/openShopcard/shop_id/' + that.data.shop_id, function (res) {
      wx.showToast({
        title: res.data.err_msg,
      })
      that.onLoad();
    })
    
  },
  jump: function(options) {
    let that = this;
    var url = options.currentTarget.dataset.url;
    var id = options.currentTarget.dataset.id;
    var wid = this.data.info.wid;

    //显示协议
    if (url == 'showABS') {
      app.ihttpGet('https://www.58zltc.com/api.php/Shop/getCardInfo/shop_id/' + that.data.shop_id, function (resq) {
        wx.hideLoading();
        setTimeout(function () {
          if (resq.data == null) {
            that.setData({
              showShopJoinAgreement: 1
            })
          } else if (resq.data.status == 0) {
            wx.showToast({
              icon: 'none',
              title: '审核中，请耐心等待',
              duration: 1500,
            })
          } else if (resq.data.status == 1) {
            wx.navigateTo({
              url: '/pages/mine/shop/card/joincard' + "?shop_id=" + id + "&wid=" + wid,
            })
          }
        }, 200)
      })
    } else {
      if (url != "withdraw" && url != "withdrawlist") {
        url = url + "?shop_id=" + id + "&wid=" + wid;
        wx.navigateTo({
          url: url,
        })
      } else {
        url = url + "?shop_id=" + id + "&wid=" + wid;
        wx.navigateTo({
          url: url,
        })
      }
    }
  },
  jump_vip:function(options){
    var t = this
    wx.showModal({
      title: '提示',
      cancelText:'关闭',
      cancelColor:'#323232',
      confirmText:'前往',
      confirmColor:'#ec5e2a',
      content: '此功能为付费功能，是否前往查看？',
      success:function(o){
        if(o.confirm){
          var url = options.currentTarget.dataset.url;
          var id = options.currentTarget.dataset.id;
          var type_num = options.currentTarget.dataset.type_num;
          var wid = t.data.info.wid;
          // wx.showToast({
          //   icon:'none',
          //   title: '开发中，敬请期待！',
          // })
          wx.navigateTo({
            url: '/pages/mine/shop/vip?type_num=' + type_num,
          })
        }
      }
    })
   
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  hiden_agreement: function () {
    var that = this
    this.setData({
      showShopJoinAgreement: 0
    })
    wx.navigateTo({
      url: './card/joincard?shop_id='+that.data.shop_id,
    })
  }
})